#include <bits/stdc++.h>

using namespace std;

struct sparseV
{
    int index,value;
    bool operator<(const sparseV& sv)
    {
        return this->index<sv.index;
    }
};
int main_63()
{
    int n,a,b,idx,val;
    long long ans=0;
    sparseV now,next;
    scanf("%d%d%d",&n,&a,&b);
    int len=a+b;
    sparseV uv[len];
    for (int i=0;i<len ;++i )
    {
        scanf("%d%d",&idx,&val);
        uv[i].index=idx;
        uv[i].value=val;
    }
    sort(uv,uv+len);
    --len;
    for (int i=0;i<len ;++i )
    {
        now=uv[i],next=uv[i+1];
        if (now.index==next.index)
        {
            ans+=now.value*next.value;
        }
    }
    printf("%lld",ans);
    return 0;
}
